<?php
namespace common\models;

use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;

/**
 * 广告模型
 * @author ZCY
 */
class ARNeed extends ActiveRecord
{

    const TYPE_IN = 1; //买入
    const TYPE_OUT = 2; //卖出

    const SCENARIO_BUY = 'buy';
    const SCENARIO_SELL = 'sell';
    
    const TRANS_MODE_BROKER = 1;     //有经纪人
    const TRANS_MODE_UNBROKER = 2;   //无经纪人
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%need}}';
    }

    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    public function scenarios()
    {
        return [
            self::SCENARIO_BUY  => ['uid', 'country', 'provinces', 'type', 'paymode', 'coin', 'currency', 'price', 'amount_min', 'amount_max','trans_mode','amount_trading', 'amount_used', 'amount_remain', 'meno', 'expired_at'],
            self::SCENARIO_SELL => ['uid', 'country', 'provinces', 'type', 'paymode', 'coin', 'currency', 'price', 'amount_min', 'amount_max','trans_mode','amount_trading', 'amount_used', 'amount_remain', 'meno', 'expired_at'],
        ];
    }

    /**
     * 获取用户信息
     */
    public function getUser()
    {
        return $this->hasOne(ARUser::className(), ['id' => 'uid']);
    }

    /**
     * 获取评分信息
     */
    public function getScoring()
    {
        return $this->hasOne(ARUserScoring::className(), ['uid' => 'uid']);
    }

    /**
     * 获取支付类型
     */
    public function getWallet()
    {
        return $this->hasOne(ARWallet::className(), ['id' => 'paymode']);
    }

    /**
     * 获取虚拟币信息
     */
    public function getCoinType()
    {
        return $this->hasOne(ARCoinType::className(), ['id' => 'coin']);
    }
    
    /**
     * 获取法币信息
     */
    public function getCurrencyType()
    {
        return $this->hasOne(ARCurrencyType::className(), ['id' => 'currency']);
    }
}
